library("rjson")
# Read any files on disk
files <- list.files(path = "tmp", pattern = "*.json", full.names = TRUE)
stopifnot(length(files) > 0)
# Extract the interesting bits
extract <- function(f){
json <- fromJSON(file = f)
sapply(json$Data, function(x) x$open)
}
prices <-as.data.frame(sapply(files, extract))
# Plot prices and linear regression
linear_regression <- function(name) {
# Get prices for token
y <- unlist(prices[which(colnames(prices) == name)])
x <- 1:length(y) / 60
# Fit line
relation <- lm(y ~ x)
# Plot with calculated line
plot(x, y, col = "darkred", main = name,
abline(relation), xlab = "hours", ylab = "USD")
}
plots <- sapply(colnames(prices), linear_regression)